﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace JEdwonTune {
    public partial class FrmMDIChild : Form {
        private TabControl tabCtrl;
        private TabPage tabPag;
        public TabControl TabCtrl {
            set { this.tabCtrl = value; }
        }
        public TabPage TabPag {
            get { return this.tabPag; }
            set { this.tabPag = value; }
        }

        public FrmMDIChild() {
            InitializeComponent();
            this.Closing += new System.ComponentModel.CancelEventHandler(this.MDIChild_Closing);
            this.Activated += new System.EventHandler(this.MDIChild_Activated);

        }

        private void MDIChild_Closing(object sender, System.ComponentModel.CancelEventArgs e) {
            //Destroy the corresponding Tabpage when closing MDI child form
            if (this.tabPag != null)
                this.tabPag.Dispose();

            //If no Tabpage left
            if (this.tabCtrl != null && !tabCtrl.HasChildren) {
                tabCtrl.Visible = false;
            }
        }

        private void MDIChild_Activated(object sender, System.EventArgs e) {
            //Activate the corresponding Tabpage
            tabCtrl.SelectedTab = tabPag;

            if (!tabCtrl.Visible) {
                tabCtrl.Visible = true;
            }
        }



    }
}
